﻿@model MessageEditModel
@{
    long toUserId = Request.QueryString.Get<long>("toUserId", 0);
    int maxReceiver = ViewData.Get<int>("maxReceiver", 6);
}
@using (Html.BeginAjaxForm("_CustomCreateMessage", "ControlPanelOperation", new { spaceKey = Url.SpaceKey() }, FormMethod.Post, new AjaxFormOptions().SetOnSuccessCallBack("success")))
{
  <div class="tnc-create-msg">
    <div class="tnc-dailog-pd">
        <div class="tn-form">
            <div class="tn-form-row">
                @if (toUserId > 0)
                {
                    @Html.TextBox("ToUserDisplayName", ViewData.Get<string>("ToUserDisplayName", string.Empty), InputWidthTypes.Medium, new RouteValueDictionary { { "readOnly", "readOnly" } })
                    @Html.Hidden("ToUserIds", toUserId.ToString())
                }
                else
                { 
                    @Html.UserSelector("ToUserIds", maxReceiver, null, SelectorWidthType.Long, UserSelectorSearchScope.Site)
                }
            </div>
            <div class="tn-form-row">
                @Html.TextAreaFor(model => model.Body, htmlAttributes: new RouteValueDictionary { { "id", "MessageBody" } })
            </div>
            <div class="tn-form-row tn-count">
                @Html.EmotionSelector()
				<span id="Note" class="tn-text-note">0/300</span>
            </div>
        </div>
    </div>
    <div class=" tnc-artdilog-btn tn-bg-gray tn-border-gray tn-border-top">
        @Html.Button("发送", ButtonTypes.Submit, HighlightStyles.Primary, htmlAttributes: new { id = "submitMessage" })
    </div>
  </div>
}
<script type="text/javascript">
    $(document).ready(function () {
        var countInterval;
        function blength(value) {
            return parseInt((value.replace(/[^\x00-\xff]/g, "**").length + 1) / 2);
        }
        var length = blength($("#MessageBody").val());
        function count() {
            length = blength($("#MessageBody").val());
            var $ps = $('#Note');

            $("#Note").html(length + "/300");
        }

        $("#MessageBody").focus(function () {
            countInterval = setInterval(function () { count(); }, 360);
        }).blur(function () {
            clearInterval(countInterval);
            count();
        });

        count();
        $("#submitMessage").click(function () {

            if (length > 300) {
                art.dialog.tips("最多允许输入300个字！", 1.5, 0);
                return false;
            }
        });
    });

    function success() {

        location.reload(true);
    }

</script>
<script type="text/dialog">
  var title="创建私信";
  @if (toUserId > 0)
  {
     @:title = "回复私信";
  }
    this.title(title);
</script>
